
//
//  MonthStasticsCell.m
//  PropertyMananger
//
//  Created by Mansion on 17/3/4.
//  Copyright © 2017年 BH. All rights reserved.
//

#import "MonthStasticsCell.h"

@implementation MonthStasticsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    
}
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString * CellID = @"MonthStasticsCellID";
    MonthStasticsCell * cell = [tableView dequeueReusableCellWithIdentifier:CellID];
    if (!cell) {
        
        cell = [[MonthStasticsCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
        
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        UILabel * tipLabel = [[UILabel alloc]init];
        [self.contentView addSubview:tipLabel];
        tipLabel.backgroundColor = BHColor(245, 95, 29);
        
        [tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.contentView).with.offset(15);
            make.top.equalTo(self.contentView).with.offset(15);
            make.size.mas_equalTo(CGSizeMake(2, 15));
        }];
        
        UILabel * progressLabel = [[UILabel alloc]init];
        [self.contentView addSubview:progressLabel];
        progressLabel.text = @"月工单统计";
        
        progressLabel.textAlignment = NSTextAlignmentLeft;
        progressLabel.font = BHFont(18);
        progressLabel.textColor = [UIColor blackColor];
        
        
        [progressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(tipLabel.mas_trailing).with.offset(5);
            make.centerY.equalTo(tipLabel).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(150, 25));
        }];
        
        UILabel * countLabel = [[UILabel alloc]init];
        [self.contentView addSubview:countLabel];
        countLabel.text = @"数量/单";
        
        countLabel.font = BHFont(12);
        countLabel.textColor = BHColor(51, 51, 51);
        countLabel.textAlignment = NSTextAlignmentLeft;
        
        [countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.contentView).with.offset(10);
            make.top.equalTo(progressLabel.mas_bottom).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(60, 25));
        }];
        
        self.detailBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:self.detailBtn];
        
        [self.detailBtn setTitle:@"明细 >>" forState:UIControlStateNormal];
        [self.detailBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.detailBtn.titleLabel.font = BHFont(15);
        
        [self.detailBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.trailing.equalTo(self.contentView).with.offset(-15);
            make.centerY.equalTo(tipLabel).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(70, 30));
        }];
        
        
        [self createBrokenLineUI];
    }
    
    return self;
}


- (void)createBrokenLineUI{
    
    // 初始化折线图
    self.lineChart = [[SJLineChart alloc] init];
    [self.contentView addSubview:self.lineChart];
    
    [self.lineChart mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.contentView).with.offset(10);
        make.top.equalTo(self.detailBtn.mas_bottom).with.offset(10);
        make.size.mas_equalTo(CGSizeMake(BHscreenW - 10, 200));
    }];
    
    self.lineChart.maxValue = 200;   // 最大值
    self.lineChart.yMarkTitles = @[@"0",@"40",@"80",@"120",@"160",@"200"]; // Y轴刻度标签
    
    
}
- (void)setModel:(LeaderModel *)model{
    
    _model = model;
    
    
    [self.lineChart setXMarkTitlesAndValues:@[
                                              @{ @"item":@"1月",@"count":model.monthModel.month1Count},
                                              @{@"item":@"2月",@"count":model.monthModel.month2Count},
                                              @{@"item":@"3月",@"count":model.monthModel.month3Count},
                                              @{@"item":@"4月",@"count":model.monthModel.month4Count},
                                              @{@"item":@"5月",@"count":model.monthModel.month5Count},
                                              @{@"item":@"6月",@"count":model.monthModel.month6Count},
                                              @{@"item":@"7月",@"count":model.monthModel.month7Count},
                                              @{@"item":@"8月",@"count":model.monthModel.month8Count},
                                              @{@"item":@"9月",@"count":model.monthModel.month9Count},
                                              @{@"item":@"10月",@"count":model.monthModel.month10Count},
                                              @{@"item":@"11月",@"count":model.monthModel.month11Count},
                                              @{@"item":@"12月",@"count":model.monthModel.month12Count}] titleKey:@"item" valueKey:@"count"];
    
    
    [self.lineChart mapping];
    
}


@end
